package com.taotao.controller;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.taotao.dao.MayiktIntegralInfoDao;
import com.taotao.entity.MayiktIntegralInfo;
import com.taotao.service.MayiktIntegralInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (MayiktIntegralInfo)表控制层
 *
 * @author makejava
 * @since 2022-01-23 21:08:47
 */
@Slf4j
@RestController
@RequestMapping("/mayiktIntegralInfo")
public class MayiktIntegralInfoController {
    @Autowired
    private MayiktIntegralInfoDao mayiktIntegralInfoDao;
    /**
     * 服务对象
     */
    @Resource
    private MayiktIntegralInfoService mayiktIntegralInfoService;

    @LcnTransaction
    @Transactional
    @RequestMapping(value = "/addIntegral", method = RequestMethod.POST)
    public ResponseEntity addIntegral(@RequestBody MayiktIntegralInfo integralDto) {
        try {

            int result = mayiktIntegralInfoDao.insertIntegral(integralDto);
            return result > 0 ? ResponseEntity.status(200).body("ok") : ResponseEntity.status(500).body("fail");
        } catch (Exception e) {
            log.error("<e:{}>", e);
            return ResponseEntity.status(500).body("fail");
        }
    }

    @RequestMapping(value = "/index", method = RequestMethod.POST)
    public String index() {
        System.out.println("******");
        return "index";
    }

    /**
     * 分页查询
     *
     * @param mayiktIntegralInfo 筛选条件
     * @param pageRequest        分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<MayiktIntegralInfo>> queryByPage(MayiktIntegralInfo mayiktIntegralInfo, PageRequest pageRequest) {
        return ResponseEntity.ok(this.mayiktIntegralInfoService.queryByPage(mayiktIntegralInfo, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<MayiktIntegralInfo> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.mayiktIntegralInfoService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param mayiktIntegralInfo 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<MayiktIntegralInfo> add(MayiktIntegralInfo mayiktIntegralInfo) {
        return ResponseEntity.ok(this.mayiktIntegralInfoService.insert(mayiktIntegralInfo));
    }

    /**
     * 编辑数据
     *
     * @param mayiktIntegralInfo 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<MayiktIntegralInfo> edit(MayiktIntegralInfo mayiktIntegralInfo) {
        return ResponseEntity.ok(this.mayiktIntegralInfoService.update(mayiktIntegralInfo));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.mayiktIntegralInfoService.deleteById(id));
    }

}

